#include "Join.h"
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
#include <math.h>

Join::Join(QWidget* parent) :
	BaseItem(parent)
{
}

void Join::paintEvent(QPaintEvent*event)
{
	if(nodes.count() != 2) return;
	QPainter painter(this);

	painter.setRenderHint(QPainter::Antialiasing, true);
	painter.setPen(QPen(QColor(0,0,0),5));
	QPoint p1(nodes.at(0)->x()+nodes.at(0)->width()/2, nodes.at(0)->y()+nodes.at(0)->height()/2);
	QPoint p2(nodes.at(1)->x()+nodes.at(1)->width()/2, nodes.at(1)->y()+nodes.at(1)->height()/2);
	painter.drawLine(p1.x(), p1.y(), p2.x(), p2.y());
	painter.end();

	//setPosition(0,0);//(p1.x() < p2.x() ? p1.x() : p2.x(), p1.y() < p2.y() ? p1.y() : p2.y());
	//int dx = p1.x() - p2.x();
	//int dy = p1.y() - p2.y();
	//setRect(abs(dx), abs(dy));
}

void Join::addNode(BaseItem* node)
{
	nodes.append(node);
}
